package com.joysuch.wwyt.app.controller;

import com.joysuch.wwyt.attendant.bean.AttendantRecordAppBean;
import com.joysuch.wwyt.attendant.bean.AttendantRecordProcessAppReqBean;
import com.joysuch.wwyt.attendant.bean.AttendantRecordReqAppBean;
import com.joysuch.wwyt.attendant.service.AttendantAreaService;
import com.joysuch.wwyt.attendant.service.AttendantRecordProcessService;
import com.joysuch.wwyt.attendant.service.AttendantRecordService;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.core.exception.ApiCoreException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * @author xsx
 * @version 1.0
 * @date 2023/2/16 10:31
 */
@RestController
@RequestMapping("/attendant/app/record")
@Api(tags = "app跟班管理")
public class AppAttendantRecordController {

    @Autowired
    private AttendantRecordService attendantRecordService;

    @Autowired
    private AttendantRecordProcessService attendantRecordProcessService;

    @Autowired
    private AttendantAreaService attendantAreaService;

    @GetMapping("page")
    @ApiOperation(value = "查看跟班计划 way 1是今日任务 2是本周任务 3是本月任务", response = AttendantRecordAppBean.class)
    public ResultBean page(Pageable page, Integer way) {
        return attendantRecordService.selectPage(page, way);
    }

    @GetMapping("findByPlanId")
    @ApiOperation(value = "查看跟班记录详情", response = AttendantRecordAppBean.class)
    public ResultBean findByPlanId(Long id) {
        AttendantRecordAppBean bean = attendantRecordService.findByPlanId(id);
        return ResultBean.success(bean);
    }

    @PostMapping("save")
    @ApiOperation(value = "保存记录 暂存state传0 完成state传3")
    public ResultBean save(@RequestBody AttendantRecordReqAppBean bean) throws ParseException {
        attendantRecordService.saveEntity(bean);
        return ResultBean.defaultSuccessResult();
    }

    @PostMapping("saveProcess")
    @ApiOperation(value = "保存发起隐患")
    public ResultBean saveProcess(@RequestBody AttendantRecordProcessAppReqBean bean) {
        attendantRecordProcessService.saveProcess(bean);
        return ResultBean.defaultSuccessResult();
    }



    @GetMapping("app-location-check")
    @ApiOperation(value = "位置校验")
    public ResultBean locationCheck(Long areaId, Long userId) throws ApiCoreException {
        return ResultBean.success(attendantAreaService.position(areaId,userId));
    }
}
